/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _DAL_RTICONNEXTDDS_ENTITY_GETTER_HPP_
#define _DAL_RTICONNEXTDDS_ENTITY_GETTER_HPP_

#include "dal/domain_participant.h"
#include "dal/publisher.h"
#include "dal/subscriber.h"
#include "dal/topic.h"

#include "dal_rticonnextdds/entity_impl/DalDomainParticipantImpl.hpp"
#include "dal_rticonnextdds/entity_impl/DalSubscriberImpl.hpp"
#include "dal_rticonnextdds/entity_impl/DalDataReaderImpl.hpp"
#include "dal_rticonnextdds/entity_impl/DalPublisherImpl.hpp"
#include "dal_rticonnextdds/entity_impl/DalDataWriterImpl.hpp"
#include "dal_rticonnextdds/entity_impl/DalTopicImpl.hpp"

inline DDS_DomainParticipant* get_rtidds_domain_participant(dal_domain_participant_t* participant)
{
    if (!participant || !participant->handle_) {
        return nullptr;
    }
    return static_cast<DalDomainParticipantImpl*>(participant->handle_)->RtiddsDomainParticipant();
}

inline DDS_Subscriber* get_rtidds_subscriber(dal_subscriber_t* subscriber)
{
    if (!subscriber || !subscriber->handle_) {
        return nullptr;
    }
    return static_cast<DalSubscriberImpl*>(subscriber->handle_)->RtiddsSubscriber();
}

inline DDS_DataReader* get_rtidds_datareader(dal_datareader_t* datareader)
{
    if (!datareader || !datareader->handle_) {
        return nullptr;
    }
    return static_cast<DalDataReaderImpl*>(datareader->handle_)->RtiDataReader();
}

inline DDS_Publisher* get_rtidds_publisher(dal_publisher_t* publisher)
{
    if (!publisher || !publisher->handle_) {
        return nullptr;
    }
    return static_cast<DalPublisherImpl*>(publisher->handle_)->RtiddsPublisher();
}

inline DDS_DataWriter* get_rtidds_datawriter(dal_datawriter_t* datawriter)
{
    if (!datawriter || !datawriter->handle_) {
        return nullptr;
    }
    return static_cast<DalDataWriterImpl*>(datawriter->handle_)->RtiddsDataWriter();
}

inline DDS_Topic* get_rtidds_topic(dal_topic_t* topic)
{
    if (!topic || !topic->handle_) {
        return nullptr;
    }
    return static_cast<DalTopicImpl*>(topic->handle_)->RtiddsTopic();
}

inline DDS_Topic* get_rtidds_topic_desc(dal_topic_description_t* topic_desc)
{
    if (!topic_desc || !topic_desc->handle_) {
        return nullptr;
    }
    return static_cast<DalTopicImpl*>(topic_desc->handle_)->RtiddsTopic();
}


#endif  // _DAL_RTICONNEXTDDS_ENTITY_GETTER_HPP_